package cn.tedu.boqi.shop.user.service.impl;

import cn.tedu.boqi.shop.user.mapper.UserMapper;
import cn.tedu.boqi.shop.user.pojo.dto.UserRegDTO;
import cn.tedu.boqi.shop.user.pojo.entity.User;
import cn.tedu.boqi.shop.user.pojo.vo.UserStandardVO;
import cn.tedu.boqi.shop.user.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void reg(UserRegDTO userRegDTO) {
        log.debug("开始处理【用户注册】的业务:{}",userRegDTO);
        String nickname = userRegDTO.getNickname();
        int countByNickname = userMapper.countByNickname(nickname);
        if(countByNickname>0){
            throw new RuntimeException();
        }

        User user = new User();
        BeanUtils.copyProperties(userRegDTO,user);
        log.debug("即将插入数据:{}",user);
        userMapper.insert(user);
    }
}
